﻿using System;
using System.Collections.Generic;
using System.Text;
using Ghasam.Business.Domain.Entity;
using Ghasam.Business.DAO;
using Spring.Transaction.Interceptor;

namespace Ghasam.Business.Services.Impl
{
   public class PaymentService:IPaymentService
    {
       private ICustomerDao iCustomerDao;
       public ICustomerDao ICustomerDao
       {
           set { iCustomerDao = value; }
           get { return iCustomerDao; }
       }
       private IPaymentTypeDao iPaymentTypeDao;
       public IPaymentTypeDao IPaymentTypeDao
       {
           set { iPaymentTypeDao = value; }
           get { return iPaymentTypeDao; }
       }
       private IPaymentChequeDao iPaymentChequeDao;
       public IPaymentChequeDao IPaymentChequeDao
       {
           set { iPaymentChequeDao = value; }
           get { return iPaymentChequeDao; }
       }

       [Transaction(ReadOnly = false)]
       public void PaymentSaveOrUpadate(int customerId, int paymentTypeId, int amount, string chequeNumber, string bankName, string bankBranch, DateTime chequeDate, string comment, bool cashed, string paidTo, DateTime paidDate, DateTime paymentDate, DateTime lastUpdate)
       {
           PaymentCheque payment = new PaymentCheque();
           payment.LastUpdate = lastUpdate;
           payment.PaidDate = paidDate;
           payment.Amount = amount;
           payment.BankBranch = bankBranch;
           payment.BankName = bankName;
           payment.ChequeNumber = chequeNumber;
           payment.Comment = comment;
           payment.PaidTo = paidTo;
           payment.Cashed = cashed;
           payment.PaymentDate = paymentDate;
           Customer customer = ICustomerDao.FindById(customerId);
           PaymentType paymentType = IPaymentTypeDao.FindById(paymentTypeId);
           payment.Customer = customer;
           payment.PaymentType = paymentType;
           IPaymentChequeDao.SaveOrUpdate(payment);
       }

       [Transaction(ReadOnly = false)]
       public void PaymentChequeUpdate(int paymentId, string paidTo, DateTime paidDate, string comment, DateTime lastUpdate)
       {
           PaymentCheque paymentCheque = IPaymentChequeDao.FindById(paymentId);
           paymentCheque.PaidTo = paidTo;
           paymentCheque.PaidDate = paidDate;
           paymentCheque.LastUpdate = lastUpdate;
           paymentCheque.Comment = comment;
           IPaymentChequeDao.SaveOrUpdate(paymentCheque);
       }

       public PaymentCheque FindById(int paymentid)
       {
          return iPaymentChequeDao.FindById(paymentid);
           
       }
       public IList<PaymentCheque> FindAllPaymentByParam(bool isFormal)
       {
           return IPaymentChequeDao.FindAllPaymentByParam(isFormal);
       }
   }
}
